import axios from 'axios'
const instance = axios.create({
    baseURL: "https://baidu.com/",
    timeout: 1000 * 3,
    headers: {
        "X-Custom-Header": "foobar"
    }
});
//拦截器
axios.interceptors.request.use(function (config){
    //设置token
    config.headers["token"]=sessionStorage.getItem('token')
    return config
},function (err){
    return Promise.reject(err)
})
axios.interceptors.response.use(function (res){
    return res
},function (err){
    return Promise.reject(err)
})

export const $get=async (url: string, data: object = {}) =>await instance.get(url, {data})
export const $post=async (url: string, data: object = {}) =>await instance.post(url, {data})